home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / include / glibmm-2.4 / glibmm / shell.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-04-20  |  4.2 KB  |  124 lines

  1. // -*- c++ -*-
  2. // Generated by gtkmmproc -- DO NOT MODIFY!
  3. #ifndef _GLIBMM_SHELL_H
  4. #define _GLIBMM_SHELL_H
  5.  
  6.  
  7. /* $Id: shell.hg,v 1.2 2003/01/22 21:38:35 murrayc Exp $ */
  8.  
  9. /* Copyright (C) 2002 The gtkmm Development Team
  10.  *
  11.  * This library is free software; you can redistribute it and/or
  12.  * modify it under the terms of the GNU Library General Public
  13.  * License as published by the Free Software Foundation; either
  14.  * version 2 of the License, or (at your option) any later version.
  15.  *
  16.  * This library is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19.  * Library General Public License for more details.
  20.  *
  21.  * You should have received a copy of the GNU Library General Public
  22.  * License along with this library; if not, write to the Free
  23.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  */
  25.  
  26.  
  27. #include <glib/gshell.h>
  28. #include <string>
  29.  
  30. #include <glibmm/arrayhandle.h>
  31. #include <glibmm/error.h>
  32.  
  33. #include <glibmmconfig.h>
  34. GLIBMM_USING_STD(string)
  35.  
  36.  
  37. namespace Glib
  38. {
  39.  
  40. /** @defgroup ShellUtils Shell-related Utilities
  41.  * Shell-like command line handling.
  42.  * @{
  43.  */
  44.  
  45. /** Exception class for shell utility errors.
  46.  */
  47. class ShellError : public Glib::Error
  48. {
  49. public:
  50.   enum Code
  51.   {
  52.     BAD_QUOTING,
  53.     EMPTY_STRING,
  54.     FAILED
  55.   };
  56.  
  57.   ShellError(Code error_code, const Glib::ustring& error_message);
  58.   explicit ShellError(GError* gobject);
  59.   Code code() const;
  60.  
  61. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  62. private:
  63.   static void throw_func(GError* gobject);
  64.   friend void wrap_init(); // uses throw_func()
  65. #endif
  66. };
  67.  
  68.  
  69. /** Parses a command line into an argument vector, in much the same way the
  70.  * shell would, but without many of the expansions the shell would perform
  71.  * (variable expansion, globs, operators, filename expansion, etc.\ are not
  72.  * supported).  The results are defined to be the same as those you would
  73.  * get from a UNIX98 /bin/sh, as long as the input contains none of the
  74.  * unsupported shell expansions.  If the input does contain such expansions,
  75.  * they are passed through literally.
  76.  * @param command_line Command line to parse.
  77.  * @return Array of args (The generic ArrayHandle will be implicitly
  78.  * converted to any STL compatible container type).
  79.  * @throw Glib::ShellError
  80.  */
  81. Glib::ArrayHandle<std::string> shell_parse_argv(const std::string& command_line);
  82.  
  83. /** Quotes a string so that the shell (/bin/sh) will interpret the quoted
  84.  * string to mean @a unquoted_string.  If you pass a filename to the shell,
  85.  * for example, you should first quote it with this function.  The quoting
  86.  * style used is undefined (single or double quotes may be used).
  87.  * @param unquoted_string A literal string.
  88.  * @return A quoted string.
  89.  */
  90. std::string shell_quote(const std::string& unquoted_string);
  91.  
  92. /** Unquotes a string as the shell (/bin/sh) would.  Only handles quotes; if
  93.  * a string contains file globs, arithmetic operators, variables, backticks,
  94.  * redirections, or other special-to-the-shell features, the result will be
  95.  * different from the result a real shell would produce (the variables,
  96.  * backticks, etc. will be passed through literally instead of being expanded).
  97.  * This function is guaranteed to succeed if applied to the result of
  98.  * shell_quote().  If it fails, it throws a Glib::ShellError exception.  The
  99.  * @a quoted_string need not actually contain quoted or escaped text;
  100.  * shell_unquote() simply goes through the string and unquotes/unescapes
  101.  * anything that the shell would.  Both single and double quotes are handled,
  102.  * as are escapes including escaped newlines.
  103.  *
  104.  * Shell quoting rules are a bit strange.  Single quotes preserve the literal
  105.  * string exactly.  Escape sequences are not allowed; not even <tt>\\'</tt> --
  106.  * if you want a <tt>'</tt> in the quoted text, you have to do something like
  107.  * <tt>'foo'\\''bar'</tt>.  Double quotes allow <tt>$</tt>, <tt>`</tt>,
  108.  * <tt>"</tt>, <tt>\\</tt>, and newline to be escaped with backslash.
  109.  * Otherwise double quotes preserve things literally.
  110.  *
  111.  * @param quoted_string Shell-quoted string.
  112.  * @return An unquoted string.
  113.  * @throw Glib::ShellError
  114.  */
  115. std::string shell_unquote(const std::string& quoted_string);
  116.  
  117. /** @} group ShellUtils */
  118.  
  119. } // namespace Glib
  120.  
  121.  
  122. #endif /* _GLIBMM_SHELL_H */
  123.  
  124.